package com.up.blog.controller;

import com.alibaba.fastjson.JSON;
import com.up.blog.domain.Infobean;
import com.up.blog.service.UpdateArticlesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.SQLException;
@Controller
public class UpdateConroller  {
    @Autowired
    private UpdateArticlesService updateArticles;
    @RequestMapping(value = "/update", produces = {"application/json;charset=UTF-8"})
    @ResponseBody
    public String findUserById(HttpServletRequest req, HttpServletResponse resp) {
        resp.setContentType("application/json;charset=utf8");
        String aname=req.getParameter("data1");
        String author=req.getParameter("data2");
        String content=req.getParameter("data3");
        Integer id= Integer.valueOf(req.getParameter("data4"));
        Infobean infobean=new Infobean();
        String ret=null;
        try {
            int i=updateArticles.update(aname,author,content,id);
            if(i>0){
                infobean.setCode(0);
                infobean.setMsg("修改成功！");
            }else {
                infobean.setCode(1);
                infobean.setMsg("修改失败！");
            }
            ret=JSON.toJSONString(infobean);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return ret;
    }
}
